package com.roam.service.impl;

import com.roam.DTO.SceneDetailDTO;
import com.roam.VO.SceneDetailVO;
import com.roam.entity.scene.Scene;
import com.roam.mapper.SceneInfoMapper;
import com.roam.service.SceneInfoService;
import com.roam.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SceneInfoServiceImpl implements SceneInfoService {

    @Autowired
    private SceneInfoMapper sceneInfoMapper;
    @Autowired
    private UserService userService;

    @Override
    public SceneDetailVO buildSceneDetailVO(SceneDetailDTO sceneDetailDTO) {
        Scene scene = sceneInfoMapper.getSceneBySceneDetailDTO(sceneDetailDTO);
        SceneDetailVO sceneDetailVO=new SceneDetailVO();
        sceneDetailVO.setImgs(scene.getImgs());
        sceneDetailVO.setLocation(scene.getPosition());
        sceneDetailVO.setCity(scene.getCity());
        sceneDetailVO.setTicketMessage(scene.getPrice());
        // 检查scene.getDetailInfo()返回值是否为空
        if (scene.getDetailInfo() != null) {
            List<String> introduce = scene.getDetailInfo().getIntroduce();
            if (introduce != null && !introduce.isEmpty()) {
                sceneDetailVO.setDescription(introduce.get(0));
            }
            sceneDetailVO.setOpenTime(scene.getDetailInfo().getOpenTime());
            sceneDetailVO.setPreferentialTreatmentPolicies(scene.getDetailInfo().getPreferentialTreatmentPolicy());
            sceneDetailVO.setServiceFacilities(scene.getDetailInfo().getServiceFacilities());
        }

        // 检查scene.getNearby()返回值是否为空
        if (scene.getNearby() != null) {
            sceneDetailVO.setScenes(scene.getNearby().getNearScene());
            sceneDetailVO.setRestaurants(scene.getNearby().getNearRes());
            sceneDetailVO.setShops(scene.getNearby().getNearShop());
        }
        sceneDetailVO.setPhoneNumber(scene.getPhone());
        sceneDetailVO.setCoordinate(scene.getCoordinate());
        int sceneID = sceneDetailDTO.getSceneID();
        int userID = sceneDetailDTO.getUserID();
        String city = sceneDetailDTO.getCity();
        sceneDetailVO.setVisited(userService.judgeHavenVisited(userID,sceneID,city));

        return sceneDetailVO;

    }
}
